
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/vector/basics.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:29:11 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Basic Implementation details &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="basics.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="More about Coordinate Systems" href="coordsys.html" />
    <link rel="prev" title="Introduction" href="intro.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="coordsys.html" title="More about Coordinate Systems"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="intro.html" title="Introduction"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Vector</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Basic Implementation details</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="basic-implementation-details">
<h1>Basic Implementation details<a class="headerlink" href="#basic-implementation-details" title="Permalink to this headline">¶</a></h1>
<section id="coordinate-systems-and-vectors">
<h2>Coordinate Systems and Vectors<a class="headerlink" href="#coordinate-systems-and-vectors" title="Permalink to this headline">¶</a></h2>
<p>Currently, <a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a> is able to deal with the Cartesian (also called
rectangular), spherical and other curvilinear coordinate systems.</p>
<p>A 3D Cartesian coordinate system can be initialized in <a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a> as</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The string parameter to the constructor denotes the name assigned to the
system, and will primarily be used for printing purposes.</p>
<p>Once a coordinate system (in essence, a <code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> instance)
has been defined, we can access the orthonormal unit vectors (i.e. the
<span class="math notranslate nohighlight">\(\mathbf{\hat{i}}\)</span>, <span class="math notranslate nohighlight">\(\mathbf{\hat{j}}\)</span> and
<span class="math notranslate nohighlight">\(\mathbf{\hat{k}}\)</span> vectors) and coordinate variables/base
scalars (i.e. the <span class="math notranslate nohighlight">\(\mathbf{x}\)</span>, <span class="math notranslate nohighlight">\(\mathbf{y}\)</span> and
<span class="math notranslate nohighlight">\(\mathbf{z}\)</span> variables) corresponding to it. We will talk
about coordinate variables in the later sections.</p>
<p>The basis vectors for the <span class="math notranslate nohighlight">\(X\)</span>, <span class="math notranslate nohighlight">\(Y\)</span> and <span class="math notranslate nohighlight">\(Z\)</span>
axes can be accessed using the <code class="docutils literal notranslate"><span class="pre">i</span></code>, <code class="docutils literal notranslate"><span class="pre">j</span></code> and <code class="docutils literal notranslate"><span class="pre">k</span></code>
properties respectively.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">i</span>
<span class="go">N.i</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="p">)</span>
<span class="go">&lt;class &#39;sympy.vector.vector.BaseVector&#39;&gt;</span>
</pre></div>
</div>
<p>As seen above, the basis vectors are all instances of a class called
<code class="docutils literal notranslate"><span class="pre">BaseVector</span></code>.</p>
<p>When a <code class="docutils literal notranslate"><span class="pre">BaseVector</span></code> is multiplied by a scalar (essentially any
SymPy <code class="docutils literal notranslate"><span class="pre">Expr</span></code>), we get a <code class="docutils literal notranslate"><span class="pre">VectorMul</span></code> - the product of
a base vector and a scalar.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">3</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span>
<span class="go">3*N.i</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="p">)</span>
<span class="go">&lt;class &#39;sympy.vector.vector.VectorMul&#39;&gt;</span>
</pre></div>
</div>
<p>Addition of <code class="docutils literal notranslate"><span class="pre">VectorMul</span></code> and <code class="docutils literal notranslate"><span class="pre">BaseVectors</span></code> gives rise to
formation of <code class="docutils literal notranslate"><span class="pre">VectorAdd</span></code> - except for special cases, ofcourse.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">&lt;class &#39;sympy.vector.vector.VectorAdd&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">-</span> <span class="n">N</span><span class="o">.</span><span class="n">j</span>
<span class="go">2*N.i</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">v</span> <span class="o">-</span> <span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="p">)</span>
<span class="go">&lt;class &#39;sympy.vector.vector.VectorMul&#39;&gt;</span>
</pre></div>
</div>
<p>What about a zero vector? It can be accessed using the <code class="docutils literal notranslate"><span class="pre">zero</span></code>
attribute assigned to class <code class="docutils literal notranslate"><span class="pre">Vector</span></code>. Since the notion of a zero
vector remains the same regardless of the coordinate system in
consideration, we use <code class="docutils literal notranslate"><span class="pre">Vector.zero</span></code> wherever such a quantity is
required.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">Vector</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Vector</span><span class="o">.</span><span class="n">zero</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">Vector</span><span class="o">.</span><span class="n">zero</span><span class="p">)</span>
<span class="go">&lt;class &#39;sympy.vector.vector.VectorZero&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">Vector</span><span class="o">.</span><span class="n">zero</span>
<span class="go">N.i</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Vector</span><span class="o">.</span><span class="n">zero</span> <span class="o">==</span> <span class="mi">2</span><span class="o">*</span><span class="n">Vector</span><span class="o">.</span><span class="n">zero</span>
<span class="go">True</span>
</pre></div>
</div>
<p>All the classes shown above - <code class="docutils literal notranslate"><span class="pre">BaseVector</span></code>, <code class="docutils literal notranslate"><span class="pre">VectorMul</span></code>,
<code class="docutils literal notranslate"><span class="pre">VectorAdd</span></code> and <code class="docutils literal notranslate"><span class="pre">VectorZero</span></code> are subclasses of <code class="docutils literal notranslate"><span class="pre">Vector</span></code>.</p>
<p>You should never have to instantiate objects of any of the
subclasses of <code class="docutils literal notranslate"><span class="pre">Vector</span></code>. Using the <code class="docutils literal notranslate"><span class="pre">BaseVector</span></code> instances assigned to a
<code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> instance and (if needed) <code class="docutils literal notranslate"><span class="pre">Vector.zero</span></code>
as building blocks, any sort of vectorial expression can be constructed
with the basic mathematical operators <code class="docutils literal notranslate"><span class="pre">+</span></code>, <code class="docutils literal notranslate"><span class="pre">-</span></code>, <code class="docutils literal notranslate"><span class="pre">*</span></code>.
and <code class="docutils literal notranslate"><span class="pre">/</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">-</span> <span class="mi">2</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span><span class="o">/</span><span class="mi">3</span>
<span class="go">1/3*N.i + (-2/3)*N.j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">k</span>
<span class="go">N.i + (-2)*N.j + N.k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Vector</span><span class="o">.</span><span class="n">zero</span><span class="o">/</span><span class="mi">2</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">v</span><span class="o">/</span><span class="mi">3</span><span class="p">)</span><span class="o">*</span><span class="mi">4</span>
<span class="go">4/3*N.i + (-8/3)*N.j</span>
</pre></div>
</div>
<p>In addition to the elementary mathematical operations, the vector
operations of <code class="docutils literal notranslate"><span class="pre">dot</span></code> and <code class="docutils literal notranslate"><span class="pre">cross</span></code> can also be performed on
<code class="docutils literal notranslate"><span class="pre">Vector</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">j</span> <span class="o">-</span> <span class="n">N</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v2</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">-</span> <span class="mi">4</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v2</span><span class="p">)</span>
<span class="go">-11</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">v2</span><span class="p">)</span>
<span class="go">(-1)*N.i + (-3)*N.j + (-11)*N.k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v2</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">v1</span><span class="p">)</span>
<span class="go">N.i + 3*N.j + 11*N.k</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> and <code class="docutils literal notranslate"><span class="pre">^</span></code> operators have been overloaded for the
<code class="docutils literal notranslate"><span class="pre">dot</span></code> and <code class="docutils literal notranslate"><span class="pre">cross</span></code> methods respectively.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span> <span class="o">&amp;</span> <span class="n">v2</span>
<span class="go">-11</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span> <span class="o">^</span> <span class="n">v2</span>
<span class="go">(-1)*N.i + (-3)*N.j + (-11)*N.k</span>
</pre></div>
</div>
<p>However, this is not the recommended way of performing these operations.
Using the original methods makes the code clearer and easier to follow.</p>
<p>In addition to these operations, it is also possible to compute the
outer products of <code class="docutils literal notranslate"><span class="pre">Vector</span></code> instances in <a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a>. More
on that in a little bit.</p>
</section>
<section id="sympy-operations-on-vectors">
<h2>SymPy operations on Vectors<a class="headerlink" href="#sympy-operations-on-vectors" title="Permalink to this headline">¶</a></h2>
<p>The SymPy operations of <code class="docutils literal notranslate"><span class="pre">simplify</span></code>, <code class="docutils literal notranslate"><span class="pre">trigsimp</span></code>, <code class="docutils literal notranslate"><span class="pre">diff</span></code>,
and <code class="docutils literal notranslate"><span class="pre">factor</span></code> work on <code class="docutils literal notranslate"><span class="pre">Vector</span></code> objects, with the standard SymPy API.</p>
<p>In essence, the methods work on the measure numbers(The coefficients
of the basis vectors) present in the provided vectorial expression.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">trigsimp</span><span class="p">,</span> <span class="n">diff</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span> <span class="o">+</span> <span class="n">a</span><span class="o">*</span><span class="n">c</span> <span class="o">+</span> <span class="n">b</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">c</span><span class="p">)</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span><span class="o">.</span><span class="n">factor</span><span class="p">()</span>
<span class="go">((a + b)*(b + c))*N.i + N.j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">-</span> <span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">b</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">trigsimp</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">N.i + (-cos(2*b))*N.k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">N.i + (-cos(2*b))*N.k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="go">(4*sin(b)*cos(b))*N.k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Derivative</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">(4*sin(b)*cos(b))*N.k</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Integral</span></code> also works with <code class="docutils literal notranslate"><span class="pre">Vector</span></code> instances, similar to
<code class="docutils literal notranslate"><span class="pre">Derivative</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Integral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span> <span class="o">=</span> <span class="n">a</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">j</span> <span class="o">-</span> <span class="n">N</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integral</span><span class="p">(</span><span class="n">v1</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
<span class="go">(Integral(a, a))*N.i + (Integral(sin(a), a))*N.j + (Integral(-1, a))*N.k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integral</span><span class="p">(</span><span class="n">v1</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">a**2/2*N.i + (-cos(a))*N.j + (-a)*N.k</span>
</pre></div>
</div>
</section>
<section id="points">
<h2>Points<a class="headerlink" href="#points" title="Permalink to this headline">¶</a></h2>
<p>As mentioned before, every coordinate system corresponds to a unique origin
point. Points, in general, have been implemented in <a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a> in the
form of the <code class="docutils literal notranslate"><span class="pre">Point</span></code> class.</p>
<p>To access the origin of system, use the <code class="docutils literal notranslate"><span class="pre">origin</span></code> property of the
<code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> class.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">origin</span>
<span class="go">N.origin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">origin</span><span class="p">)</span>
<span class="go">&lt;class &#39;sympy.vector.point.Point&#39;&gt;</span>
</pre></div>
</div>
<p>You can instantiate new points in space using the <code class="docutils literal notranslate"><span class="pre">locate_new</span></code>
method of <code class="docutils literal notranslate"><span class="pre">Point</span></code>. The arguments include the name(string) of the
new <code class="docutils literal notranslate"><span class="pre">Point</span></code>, and its position vector with respect to the
‘parent’ <code class="docutils literal notranslate"><span class="pre">Point</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">origin</span><span class="o">.</span><span class="n">locate_new</span><span class="p">(</span><span class="s1">&#39;P&#39;</span><span class="p">,</span> <span class="n">a</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="n">c</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">locate_new</span><span class="p">(</span><span class="s1">&#39;Q&#39;</span><span class="p">,</span> <span class="o">-</span><span class="n">b</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="p">)</span>
</pre></div>
</div>
<p>Like <code class="docutils literal notranslate"><span class="pre">Vector</span></code>, a user never has to expressly instantiate an object of
<code class="docutils literal notranslate"><span class="pre">Point</span></code>. This is because any location in space (albeit relative) can be
pointed at by using the <code class="docutils literal notranslate"><span class="pre">origin</span></code> of a <code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> as the
reference, and then using <code class="docutils literal notranslate"><span class="pre">locate_new</span></code> on it and subsequent
<code class="docutils literal notranslate"><span class="pre">Point</span></code> instances.</p>
<p>The position vector of a <code class="docutils literal notranslate"><span class="pre">Point</span></code> with respect to another <code class="docutils literal notranslate"><span class="pre">Point</span></code> can
be computed using the <code class="docutils literal notranslate"><span class="pre">position_wrt</span></code> method.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">position_wrt</span><span class="p">(</span><span class="n">Q</span><span class="p">)</span>
<span class="go">b*N.j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="o">.</span><span class="n">position_wrt</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">origin</span><span class="p">)</span>
<span class="go">a*N.i + c*N.k</span>
</pre></div>
</div>
<p>Additionally, it is possible to obtain the <span class="math notranslate nohighlight">\(X\)</span>, <span class="math notranslate nohighlight">\(Y\)</span> and <span class="math notranslate nohighlight">\(Z\)</span>
coordinates of a <code class="docutils literal notranslate"><span class="pre">Point</span></code> with respect to a <code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code>
in the form of a tuple. This is done using the <code class="docutils literal notranslate"><span class="pre">express_coordinates</span></code>
method.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Q</span><span class="o">.</span><span class="n">express_coordinates</span><span class="p">(</span><span class="n">N</span><span class="p">)</span>
<span class="go">(a, 0, c)</span>
</pre></div>
</div>
</section>
<section id="dyadics">
<h2>Dyadics<a class="headerlink" href="#dyadics" title="Permalink to this headline">¶</a></h2>
<p>A dyadic, or dyadic tensor, is a second-order tensor formed by the
juxtaposition of pairs of vectors. Therefore, the outer products of vectors
give rise to the formation of dyadics. Dyadic tensors have been implemented
in <a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a> in the <code class="docutils literal notranslate"><span class="pre">Dyadic</span></code> class.</p>
<p>Once again, you never have to instantiate objects of <code class="docutils literal notranslate"><span class="pre">Dyadic</span></code>.
The outer products of vectors can be computed using the <code class="docutils literal notranslate"><span class="pre">outer</span></code>
method of <code class="docutils literal notranslate"><span class="pre">Vector</span></code>. The <code class="docutils literal notranslate"><span class="pre">|</span></code> operator has been overloaded for
<code class="docutils literal notranslate"><span class="pre">outer</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="p">)</span>
<span class="go">(N.i|N.j)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="o">|</span><span class="n">N</span><span class="o">.</span><span class="n">j</span>
<span class="go">(N.i|N.j)</span>
</pre></div>
</div>
<p>Similar to <code class="docutils literal notranslate"><span class="pre">Vector</span></code>, <code class="docutils literal notranslate"><span class="pre">Dyadic</span></code> also has subsequent subclasses like
<code class="docutils literal notranslate"><span class="pre">BaseDyadic</span></code>, <code class="docutils literal notranslate"><span class="pre">DyadicMul</span></code>, <code class="docutils literal notranslate"><span class="pre">DyadicAdd</span></code>. As with <code class="docutils literal notranslate"><span class="pre">Vector</span></code>,
a zero dyadic can be accessed from <code class="docutils literal notranslate"><span class="pre">Dyadic.zero</span></code>.</p>
<p>All basic mathematical operations work with <code class="docutils literal notranslate"><span class="pre">Dyadic</span></code> too.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">dyad</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dyad</span><span class="o">*</span><span class="mi">3</span>
<span class="go">3*(N.i|N.k)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dyad</span> <span class="o">-</span> <span class="n">dyad</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dyad</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="o">|</span><span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="p">)</span>
<span class="go">(N.i|N.k) + 2*(N.j|N.i)</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">dot</span></code> and <code class="docutils literal notranslate"><span class="pre">cross</span></code> also work among <code class="docutils literal notranslate"><span class="pre">Dyadic</span></code> instances as well as
between a <code class="docutils literal notranslate"><span class="pre">Dyadic</span></code> and <code class="docutils literal notranslate"><span class="pre">Vector</span></code> (and also vice versa) - as per the
respective mathematical definitions. As with <code class="docutils literal notranslate"><span class="pre">Vector</span></code>, <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> and
<code class="docutils literal notranslate"><span class="pre">^</span></code> have been overloaded for <code class="docutils literal notranslate"><span class="pre">dot</span></code> and <code class="docutils literal notranslate"><span class="pre">cross</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="o">|</span><span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="p">)</span>
<span class="go">(N.i|N.j)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="p">)</span>
<span class="go">N.i</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">i</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="go">N.j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">k</span> <span class="o">^</span> <span class="n">d</span>
<span class="go">(N.j|N.j)</span>
</pre></div>
</div>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Basic Implementation details</a><ul>
<li><a class="reference internal" href="#coordinate-systems-and-vectors">Coordinate Systems and Vectors</a></li>
<li><a class="reference internal" href="#sympy-operations-on-vectors">SymPy operations on Vectors</a></li>
<li><a class="reference internal" href="#points">Points</a></li>
<li><a class="reference internal" href="#dyadics">Dyadics</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="intro.html"
                        title="previous chapter">Introduction</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="coordsys.html"
                        title="next chapter">More about Coordinate Systems</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/vector/basics.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="coordsys.html" title="More about Coordinate Systems"
             >next</a> |</li>
        <li class="right" >
          <a href="intro.html" title="Introduction"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Vector</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Basic Implementation details</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/vector/basics.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:29:12 GMT -->
</html>